package com.gking.aiService.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.gking.aiService.entity.dto.PagingQuerySyLogsRecordDto;
import com.gking.aiService.entity.SyLogsRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SyLogsRecordMapper extends BaseMapper<SyLogsRecord> {

    /**
     * 分页条件查询的日志信息
     *
     * @param page      分页信息
     * @param account   访问者账号
     * @param nickname  访问者昵称
     * @param userId    用户id
     * @param path      访问路径
     * @param accessStatus    访问状态
     * @param responseStatus    响应状态
     * @param ipAddress ip地址
     * @return 分页条件查询的日志列表
     */
    @Select("<script>" +
            "SELECT DISTINCT l.id, l.accessUserId, l.accessPath, l.requestBody , l.accessStatus, l.consumeTime, l.createTime, l.ipAddress, l.equipmentInfo, l.responseStatus, l.responseMessage " +
            ", u.account, u.nickname " +
            "FROM sy_logs_record l " +
            "LEFT JOIN sy_user u ON u.id = l.accessUserId " +
            "WHERE " +
            "l.isDelete = 0 " +
            "<if test='account != null and account.trim() neq \"\"'> AND u.account LIKE CONCAT('%', #{account}, '%') </if> " +
            "<if test='nickname != null and nickname.trim() neq \"\"'> AND u.nickname LIKE CONCAT('%', #{nickname}, '%') </if> " +
            "<if test='userId != null and userId.trim() neq \"\"'> AND u.id LIKE CONCAT('%', #{userId}, '%') </if> " +
            "<if test='path != null and path.trim() neq \"\"'> AND l.accessPath LIKE CONCAT('%', #{path}, '%') </if> " +
            "<if test='accessStatus != null and accessStatus.trim() neq \"\"'> AND l.accessStatus LIKE CONCAT('%', #{accessStatus}, '%') </if> " +
            "<if test='responseStatus != null and responseStatus.trim() neq \"\"'> AND l.responseStatus LIKE CONCAT('%', #{responseStatus}, '%') </if> " +
            "<if test='ipAddress != null and ipAddress.trim() neq \"\"'> AND l.ipAddress LIKE CONCAT('%', #{ipAddress}, '%') </if> " +
            "ORDER BY l.createTime DESC " +
            "</script>")
    @InterceptorIgnore(tenantLine = "true")
    IPage<PagingQuerySyLogsRecordDto> findLogsRecordByCriteria(Page<PagingQuerySyLogsRecordDto> page,
                                                               @Param("account") String account,
                                                               @Param("nickname") String nickname,
                                                               @Param("userId") String userId,
                                                               @Param("path") String path,
                                                               @Param("accessStatus") String accessStatus,
                                                               @Param("responseStatus") String responseStatus,
                                                               @Param("ipAddress") String ipAddress);

}
